#!/usr/bin/python
# Checkout program for adxl345 accelerometer

I2C_BUS_NUMBER = 3
ADXL_ADDR = 0x53

from smbus import SMBus

b = SMBus(I2C_BUS_NUMBER)

#initalization

# sets normal power and 12.5Hz sample rate
b.write_byte_data(ADXL_ADDR,0x2C,0x07) 

# sets accel to measure mode
b.write_byte_data(0x53,0x2D,0x08)

while True:
	X_raw = (b.read_byte_data(0x53,0x33) << 8 ) + b.read_byte_data(0x53,0x32)
	Y_raw = (b.read_byte_data(0x53,0x35) << 8 ) + b.read_byte_data(0x53,0x34)
	Z_raw = (b.read_byte_data(0x53,0x37) << 8 ) + b.read_byte_data(0x53,0x36)
	print repr(X_raw).rjust(8), repr(Y_raw).rjust(16), repr(Z_raw).rjust(24)

